import { defineStore } from 'pinia'
import { ref } from 'vue'

/**
 * 新闻
 */

const useNews = defineStore(
  'news',
  () => {
    const searchData = ref({})

    const key = ref(0)
    const setKey = () => {
      key.value++
    }

    const reset = () => {
      searchData.value = {}
      key.value = 0
    }

    // 当前分类、分页
    const state = ref({})
    const setState = (data) => {
      state.value = data
    }

    return {
      searchData,
      key,
      setKey,
      reset,
      state,
      setState
    }
  },
  {
    persist: {
      enabled: true,
      strategies: [
        {
          storage: localStorage
        }
      ]
    }
  }
)

export default useNews
